﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebLibSolPedBE;

namespace WebApplication1
{     
    public partial class formPedidoAbiertoDet : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            PedidoAbiertoCabBE it = (PedidoAbiertoCabBE)Session["objPA"];
            if (it != null)
            {
                lblPed.Text = it.EBELN;
                lblFecha.Text = it.BEDAT;
                lblProveedor.Text = it.VALOR1.Trim();
                lblMonto.Text = it.KTWRT;
                lblUsuario.Text = it.ERNAM;
                
                CargarLista(it.EBELN);
            } 


        }

        private void CargarLista(string po_number)
        {
            List<PedidoAbiertoDetBE> lst = LibSolPedDALF.DaoFactory.PedidoAbiertoF.getLstPedidoAbiertoDet(po_number);
            gvGrid.DataSource = lst;
            gvGrid.DataBind();
        }


        protected void gvGrid_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //Find the control
                var lblEBELP = (Label)e.Row.FindControl("lblEBELP");
                var lblTXZ01_KTMNG_MEINS = (Label)e.Row.FindControl("lblTXZ01_KTMNG_MEINS");
                var lblNETPR_WAERS_WERKS = (Label)e.Row.FindControl("lblNETPR_WAERS_WERKS");

                var lblCeCo = (Label)e.Row.FindControl("lblCeCo");
                var lblOrden = (Label)e.Row.FindControl("lblOrden");
                var lblCtaCon = (Label)e.Row.FindControl("lblCtaCon");
                //Display the data
                var data = e.Row.DataItem;
                PedidoAbiertoDetBE it = (PedidoAbiertoDetBE)data;
                lblEBELP.Text = it.EBELP ;
                lblTXZ01_KTMNG_MEINS.Text = it.TXZ01 + " " + it.KTMNG + " " + it.MEINS;
                lblNETPR_WAERS_WERKS.Text = it.NETPR + " " + it.WAERS + "-" + it.WERKS;

                lblCeCo.Text = it.VALOR1.Trim();
                lblOrden.Text = it.VALOR2.Trim();
                lblCtaCon.Text = it.VALOR3.Trim();
            }
        }
    }
}